<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <script src="/ajax.js"></script>
</head>
<body>
<p>
    <label for="name">姓名</label>
    <input type="text" name="name" id="name" onblur="setValue(this.name, this.value)">
</p>
<p>
    性别
    <label>男<input type="radio" name="sex" value="男" onblur="setValue(this.name, this.value)"></label>
    <label>女<input type="radio" name="sex" value="女" onblur="setValue(this.name, this.value)"></label>
</p>
<p>
    <label for="age">年龄</label>
    <input type="number" name="age" id="age" onblur="setValue(this.name, this.value)">
</p>
<p>
    <label for="did">部门</label>
    <select name="did" id="did" onblur="setValue(this.name, this.value)">
        <option th:each="d:${ds}" th:value="${d.id}" th:text="${d.name}"></option>
    </select>
</p>
<button onclick="printMap()">添加</button>
</body>
<script>
    let map = new Map;

    let setValue = function (name, value) {
        map.set(name, value);
    }

    let printMap = function () {
        console.log(map);
        let emp = {};
        map.forEach((k, v)=>{
            emp[v] = k;
        })
        console.log(emp);
        ajax({
            url: '/map/insert',
            type: 'POST',
            dataType: 'json',
            // data: map,
            data: {"did":"1","name":"4","age":"34","sex":"34"},
            success: function (response, xml) {
                location.href = '/list'
            },
            error: function (status) {
                console.log("error")
                console.log(status)
            }
        });
    }



</script>
</html>